package com.itcast.donkey.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itcast.donkey.R;
import com.itcast.donkey.adapters.TravelAdapter;
import com.itcast.donkey.fragments.PersonalPublicFragment;

import java.util.ArrayList;

/**
 * Created by lanouhn on 16/9/18.
 */
public class PersonalActivity extends AppCompatActivity implements View.OnClickListener {

    private LinearLayout linScenicSpot;
    private ImageView backScenicApot;
    private ImageView ivChanScenicSpot;
    private TextView tvTitleScenicSpot;
    private ImageView ivHeadIcon;
    private TextView tvHeadName;
    private TextView tvHeadTitle;
    private ImageView ivHeadImage;
    private TabLayout tabLayoutHead;
    private ImageView tvPopwindow;
    private ViewPager viewpagerPersonalHead;

    private PersonalPublicFragment fragment1, fragment2, fragment3;
    private String[] tabName = {"游记", "收藏", "喜欢"};
    private ArrayList<Fragment> fragments = new ArrayList<>();

    private TravelAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personal);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        linScenicSpot = (LinearLayout) findViewById(R.id.lin_scenic_spot);
        backScenicApot = (ImageView) findViewById(R.id.back_scenic_apot);
        ivChanScenicSpot = (ImageView) findViewById(R.id.iv_chan_scenic_spot);
        tvTitleScenicSpot = (TextView) findViewById(R.id.tv_title_scenic_spot);
        ivHeadIcon = (ImageView) findViewById(R.id.iv_head_icon);
        tvHeadName = (TextView) findViewById(R.id.tv_head_name);
        tvHeadTitle = (TextView) findViewById(R.id.tv_head_title);
        ivHeadImage = (ImageView) findViewById(R.id.iv_head_image);
        tabLayoutHead = (TabLayout) findViewById(R.id.tabLayout_head);
        tvPopwindow = (ImageView) findViewById(R.id.tv_popwindow);
        viewpagerPersonalHead = (ViewPager) findViewById(R.id.viewpager_personal_head);
    }

    private void initData() {

        fragment1 = new PersonalPublicFragment();
        fragment2 = new PersonalPublicFragment();
        fragment3 = new PersonalPublicFragment();
        fragments.add(fragment1);
        fragments.add(fragment2);
        fragments.add(fragment3);
        adapter = new TravelAdapter(getSupportFragmentManager(), fragments, tabName);
        viewpagerPersonalHead.setAdapter(adapter);
        tabLayoutHead.setSelectedTabIndicatorColor(Color.BLUE);
        tabLayoutHead.setupWithViewPager(viewpagerPersonalHead);

    }

    private void initEvent() {
        backScenicApot.setOnClickListener(this);
        ivChanScenicSpot.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.back_scenic_apot:
            case R.id.iv_chan_scenic_spot:
                Intent intent = new Intent(PersonalActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
                break;
        }
    }
}
